/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.City;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class CityFetcher implements Fetcher<City>
{

    @Override
    public City fetch( ResultSet ps ) throws Exception
    {
        City c = new City();
        
        c.setId( ps.getInt( 1 ) );
        c.setHomeStateId( ps.getInt( 2 ) );
        c.setName( ps.getString( 3 ) );
        
        return c;
    }

    @Override
    public void insert( City value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_cities" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getHomeStateId());
        ps.setString( 3, value.getName() );
    }

    @Override
    public void update( City value, PreparedStatement ps ) throws Exception
    {
        ps.setString( 1, value.getName() );
        ps.setInt( 2, value.getHomeStateId());
        ps.setInt( 3, value.getId() );
    }
    
}
